package io.github.lee.jel.ui.item.list

import android.content.Context
import android.content.Intent
import androidx.core.os.bundleOf
import androidx.databinding.ViewDataBinding
import dagger.hilt.android.AndroidEntryPoint
import io.github.lee.core.ui.BaseActivity
import io.github.lee.core.util.getBundleParcelable
import io.github.lee.core.vm.BaseViewModel
import io.github.lee.jel.R
import io.github.lee.jel.domain.Item

@AndroidEntryPoint
class ItemListActivity : BaseActivity<ViewDataBinding, BaseViewModel>() {
    companion object {
        private const val KEY_ITEM = "ITEM"

        @JvmStatic
        fun start(
            context: Context, item: Item
        ) {
            val starter = Intent(context, ItemListActivity::class.java)
                .putExtras(
                    bundleOf(
                        KEY_ITEM to item,
                    )
                )
            context.startActivity(starter)
        }
    }

    //===Desc:=============================================================


    override fun onSetViewData() {
        super.onSetViewData()
        val item = getBundleParcelable(KEY_ITEM, Item::class.java)
        if (null == item) {
            toast(getString(R.string.error_application_error))
            finish()
            return
        }
        replaceFragment(ItemListFragment.newInstance(item))
    }
}